﻿<UserControl x:Class="MaxStoreShop.CoreModule.Users.UsersView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:converters="clr-namespace:MaxStoreErp.Core.Converters;assembly=MaxStoreErp.Core"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:directories="clr-namespace:MaxStoreShop.Domain.Directories;assembly=MaxStoreShop.Domain"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:ui="clr-namespace:MaxStoreShop.Core.Ui;assembly=MaxStoreShop.Core"
             xmlns:users="clr-namespace:MaxStoreShop.CoreModule.Users"
             xmlns:validators="clr-namespace:MaxStoreShop.Logic.Validators;assembly=MaxStoreShop.Logic"
             d:DataContext="{d:DesignInstance users:UsersViewModel}"
             d:DesignHeight="300"
             d:DesignWidth="300"
             mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Images.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <converters:NullImageConverter x:Key="NullImageConverter" />
        </ResourceDictionary>

    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ui:ExtendedDataGrid Name="MainDataGrid"
                             AutoGenerateColumns="False"
                             CanUserAddRows="True"
                             CanUserDeleteRows="False"
                             CanUserSortColumns="True"
                             ItemsSource="{Binding Users}"
                             SelectedItem="{Binding SelectedUser,
                                                    Mode=TwoWay}">
            <DataGrid.RowValidationRules>
                <validators:StoreUserValidator ValidationStep="UpdatedValue" />
            </DataGrid.RowValidationRules>
            <!--  <DataGrid.RowValidationErrorTemplate>  -->
            <!--  <ControlTemplate>  -->
            <!--  <Grid Margin="0,-2,0,-2" ToolTip="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}, Path=(Validation.Errors)[0].ErrorContent}">  -->
            <!--  <Ellipse Width="{TemplateBinding FontSize}"  -->
            <!--  Height="{TemplateBinding FontSize}"  -->
            <!--  Fill="Red"  -->
            <!--  StrokeThickness="0" />  -->
            <!--  <TextBlock HorizontalAlignment="Center"  -->
            <!--  FontSize="{TemplateBinding FontSize}"  -->
            <!--  FontWeight="Bold"  -->
            <!--  Foreground="White"  -->
            <!--  Text="!" />  -->
            <!--  </Grid>  -->
            <!--  </ControlTemplate>  -->
            <!--  </DataGrid.RowValidationErrorTemplate>  -->
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Фото" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Width="64"
                                   Height="64"
                                   Source="{Binding FotoRaw,
                                                    Converter={StaticResource NullImageConverter}}"
                                   d:DataContext="{d:DesignInstance directories:StoreUser}">
                                <Image.ToolTip>
                                    <Image Width="300"
                                           Height="300"
                                           Source="{Binding FotoRaw,
                                                            Converter={StaticResource NullImageConverter}}"
                                           d:DataContext="{d:DesignInstance directories:StoreUser}" />
                                </Image.ToolTip>
                            </Image>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Width="*"
                                    Binding="{Binding FirstName,
                                                      UpdateSourceTrigger=PropertyChanged}"
                                    Header="Имя"
                                    IsReadOnly="False" />
                <DataGridTextColumn Width="*"
                                    Binding="{Binding LastName,
                                                      UpdateSourceTrigger=PropertyChanged}"
                                    Header="Фамилия"
                                    IsReadOnly="False" />
            </DataGrid.Columns>
        </ui:ExtendedDataGrid>

        <ToolBar Name="MyToolBar"
                 Grid.Row="1"
                 Visibility="Collapsed">
            <ToolBar.Items>
                <Button Width="44"
                        Height="44"
                        BorderThickness="0"
                        Command="{Binding ChangePhotoCommand}"
                        IsDefault="True"
                        Style="{DynamicResource MetroCircleButtonStyle}"
                        ToolTip="Сменить фотографию пользователя">
                    <Path Width="32"
                          Height="32"
                          Data="{StaticResource UserPhotoIcon}"
                          Fill="{DynamicResource BlackBrush}"
                          Stretch="Uniform" />
                </Button>
                <Button Width="44"
                        Height="44"
                        BorderThickness="0"
                        Command="{Binding ChangePasswordCommand}"
                        IsDefault="True"
                        Style="{DynamicResource MetroCircleButtonStyle}"
                        ToolTip="Сменить пароль пользователя">
                    <Path Width="32"
                          Height="32"
                          Data="{StaticResource PasswordIcon}"
                          Fill="{DynamicResource BlackBrush}"
                          Stretch="Uniform" />
                </Button>
            </ToolBar.Items>
        </ToolBar>
    </Grid>
</UserControl>
